using System;
using System.Collections;
using System.IO;

namespace PacSnake
{
	/// <summary>
	/// This class holds a collection of Skin objects.
	/// </summary>
	public class SkinCollection
	{
        // Collection of Skin objects
        private ArrayList skins = new ArrayList();
        
        // Read current path and remove the 'file:/' from the string
        private string path = Path.GetDirectoryName(System.Reflection.Assembly.
            GetExecutingAssembly().GetName().CodeBase).Substring(6);
        
        
        /// <summary>
        /// Loads the information of all the available skins.
        /// </summary>
        public void LoadSkins()
        {
            // Read all level set files from the levels directory
            string [] fileEntries = Directory.GetFiles(path + "\\skins");
            
            // Read the skins from the files with an .xml extension
            foreach (string filename in fileEntries)
            {
                FileInfo fileInfo = new FileInfo(filename);
                
                if (fileInfo.Extension.Equals(".xml"))
                {
                    Skin skin = new Skin();
                    skin.LoadSkin(filename);
                    skins.Add(skin);
                }
            }
        }
        
        
        /// <summary>
        /// Indexer
        /// </summary>
        /// <exception cref="System.ArgumentOutOfRangeException">Throws an
        /// exception when an invalid index is passed to the indexer. An index
        /// is invalid when it's negative, or greater than the size of the
        /// collection</exception>
        public Skin this[int index]
        {
            get
            {
                if (index < 0 || index >= skins.Count)
                    throw new ArgumentOutOfRangeException("index",
                        "Index was negative or larger than the number of " +
                        "level sets in de collection.");
                
                return (Skin)skins[index];
            }
        }
        
        
        /// <summary>
        /// Returns the number of Skin objects in the collection
        /// </summary>
        public int Count
        {
            get { return skins.Count; }
        }
	}
}
